package com.chinaedu.oc.util.plugin;

import java.util.List;

import sun.security.util.Length;

/**
 * 分页插件入参
 * 使用说明：
 * 	setPageParam  设置分页参数
 * 	getPageQueryResult   获取分页结果
 * 	
 * @Description: TODO
 * @author A18ccms a18ccms_gmail_com 
 * @date 2017年5月9日 下午2:11:34 
 * 
 * @param <T>
 */
public class PageParams <T extends Object>{
	private Integer page;//当前页码
	private Integer pageSize;//每页条数
	private Boolean useFlag = true;//是否启用插件
	private Boolean CheckFlag = true;//是否检测当前页码的有效性
	private Integer total;//当前sql返回总数，插件回填
	private Integer totalPage;//sql以当前分页的总页数，插件回填
	
	private Object param;//查询参数
	private List<T> resultList;//返回参数，可以把结果直接设置进来，直接返回
	
	public PageQueryResult getPageQueryResult() {
		PageQueryResult r = new PageQueryResult();
		r.setPage(this.page);
		r.setPageSize(this.pageSize);
		r.setTotal(this.total);
		r.setTotalPage(this.totalPage);
		
		return r;
	}
	
	/**
	 * 
	 * @Description: TODO
	 * @param @param start 起始条数
	 * @param @param length  查询条数
	 * @return void    返回类型 
	 * @throws
	 */
	public void setPageParam(Integer start, Integer length) {
		
		if(start == null || length == null || length == 0) {
			this.page = 1;
			this.pageSize = Integer.MAX_VALUE;
		}else {
			this.page = start / length + 1;
			this.pageSize = length;
		}
	}
	
	
	
	
	
	
	public Boolean getUseFlag() {
		return useFlag;
	}

	public Boolean getCheckFlag() {
		return CheckFlag;
	}

	public Integer getPage() {
		return page;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public Integer getTotal() {
		return total;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Object getParam() {
		return param;
	}
	public void setParam(Object param) {
		this.param = param;
	}
	public List<T> getResultList() {
		return resultList;
	}
	public void setResultList(List<T> resultList) {
		this.resultList = resultList;
	}
	@Override
	public String toString() {
		return "PageParams [page=" + page + ", pageSize=" + pageSize + ", useFlag=" + useFlag + ", CheckFlag="
				+ CheckFlag + ", total=" + total + ", totalPage=" + totalPage + "]";
	}
}
